//
//  CTMLCell.m
//  09-静态单元格
//
//  Created by Sizhu Ba on 2017/9/10.
//  Copyright © 2017年 mac. All rights reserved.
//
#define QDEV_W = UIScreen.mainScreen.bounds.size.width
#import "CTMLCell.h"
#import <UIKit/UIKit.h>
#import "MLNodelObj.h"
@interface CTMLCell ()
 
@property (nonatomic, strong) UIView * bgv;
@property (nonatomic, strong) UILabel * descLbl;
@property (nonatomic, strong) UIButton * imgBtn;
@end


@implementation CTMLCell

- (void)awakeFromNib {
    [super awakeFromNib];
   
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

   
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
   
    self  =  [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    self.contentView.frame = [self QRect:0 andY:0 andW:UIScreen.mainScreen.bounds.size.width andH:50];
    
    [self creatsubview];
    return self;
}

-(void)creatsubview {
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    self.bgv = [[UIView alloc]initWithFrame:CGRectMake(15, 0, UIScreen.mainScreen.bounds.size.width-30, 50)];
    self.bgv.backgroundColor = [self RGBAsame:245.0 andA:1.0];
    self.bgv.layer.borderColor =[[self RGBAsame:211 andA:1.0] CGColor];//边框颜色
    self.bgv.layer.borderWidth = 1.0;//设置边框
    
    CGFloat imgw = 30.0;
    self.imgBtn = [[UIButton alloc]initWithFrame:CGRectMake(self.bgv.frame.size.width-imgw, (self.bgv.frame.size.height-imgw)/2.0, imgw, imgw)];
    //self.imgBtn.userInteractionEnabled = false;
    [self.imgBtn setImage:[UIImage imageNamed:@"unopen"] forState:UIControlStateNormal];
    [self.imgBtn setImage:[UIImage imageNamed:@"open"] forState:UIControlStateSelected];
    
     self.imgBtn.imageView.contentMode = UIViewContentModeScaleAspectFit; //图片缩放
    self.imgBtn.contentEdgeInsets = UIEdgeInsetsMake(10, 10, 10, 10);
    [self.bgv addSubview:self.imgBtn];
    
    
    self.descLbl = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, self.bgv.frame.size.width-imgw-10, self.bgv.frame.size.height )];
    self.descLbl.font = [UIFont systemFontOfSize:13.0];
    self.descLbl.textColor = [UIColor blackColor];
    self.descLbl.text = @"测试用的";
    //self.textAlignment = NSTextAlignmentLeft;
    self.bgv.backgroundColor = self.bgv.backgroundColor;
    
    [self.bgv addSubview:self.descLbl];
    
    [self addSubview:self.bgv];
}
-(void)setcellinfo:(NSObject *)obj {
    
    MLNodelObj * mLNodelObj = (MLNodelObj *) obj;
    self.descLbl.text = mLNodelObj.name;
    [self.imgBtn setSelected:mLNodelObj.expand];
    [self.imgBtn setHidden: mLNodelObj.leaf];
    [self layoutView:mLNodelObj];
    
}
-(void)layoutView:(MLNodelObj *)obj {
    
    CGFloat interval  = 30;
    CGFloat leMargin  = 10;
    for (int i = 2 ; i< obj.level+1 ; i ++){
        leMargin += interval;
    }
    self.descLbl.frame = CGRectMake(leMargin, 0, self.bgv.frame.size.width-leMargin-30, self.bgv.frame.size.height);
    self.bgv.backgroundColor = obj.level == 2 ? [self RGBAsame:245.0 andA:1.0] : [self RGBAsame:255.0 andA:1.0];
    self.descLbl.backgroundColor = self.bgv.backgroundColor; //[UIColor redColor];
}
/**
 * 宽度
 */
-(CGFloat)GETVW:(UIView *)view {
    
    return view.frame.size.width;
    
}
/**
 * 高度
 */
-(CGFloat)GETVH:(UIView *)view {
    
    return view.frame.size.height;
    
}
/**
 * 获取rect
 */
-(CGRect)QRect:(CGFloat)x andY:(CGFloat) y  andW:(CGFloat ) w andH:(CGFloat) h{
    
    return CGRectMake(x, y, w, h);
    
}
/**
 * 设置颜色
 */
-(UIColor *)RGBAsame:(CGFloat) RGB andA:(CGFloat) A {
    
    return [UIColor colorWithRed:RGB/255.0 green:RGB/255.0 blue:RGB/255.0 alpha:A];
    
}
@end
